#include "TCPTaskPool.h"
#include "SuperTaskManager.h"
#include "SuperTimeTick.h"
#include "SuperServer.h"

void SuperServer::newTCPTask(int connfd, struct sockaddr_in * client )
{
	SuperTask * task = new SuperTask(connfd, client);
	if ( NULL == task )
		TEMP_FAILURE_RETRY(::close(connfd));
	else if ( !pool->addVerify(task)) // ::close will be called in destructor
	{
		delete task;
	}
}

bool SuperServer::init()// override
{
	SuperTaskManager::creatInstance();
	SuperTimeTick::creatInstance();

	pool = new TCPTaskPool(256);// create thread pool
	if ( pool == NULL || !pool->init())
	{
		return false;
	}
	if ( !TCPServer::bind(this->port))
		return false;
	return SuperTimeTick::getInstance()->start();
}

int main()
{
	SuperServer::creatInstance();
	SuperServer::getInstance()->mainLoop();

	return 0;
}

